﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using DAL;
using BUS;
using Utility;
using System.Security.Cryptography;
using System.Text;
using System.Web.Security;
public partial class Admin_NhanVien_Sua : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadComboBox();
            LoadData();
        }
    }
    protected void LoadComboBox()
    {
        DropDownList_PhanQuyen.Items.Insert(0, "Quản lý");
        DropDownList_PhanQuyen.Items.Insert(1, "Nhân viên");
    }
    private void LoadData()
    {
        if (Request.QueryString["id"] == null)
            Response.Redirect("NhanVien.aspx");
        string iD = Request.QueryString["id"];
        NhanVien nv = NhanVienBUS.GetById(iD);

        if (nv != null)
        {
            txt_Password_NhanVien.Text = nv.MatKhau_NhanVien;
            txt_TenNhanVien.Text = nv.TenNhanVien;
            txt_DiaChi.Text = nv.DiaChi;
            txt_DienThoai.Text = nv.DienThoai;
            txt_Email.Text = nv.Email;
            DropDownList_PhanQuyen.SelectedIndex = nv.MaPhanQuyen;

        }
        else
        {
            Response.Redirect("NhanVien.aspx");
        }


    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        NhanVien nv = new NhanVien();
        nv.TenDangNhap_NhanVien = Request.QueryString["id"];
        string Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txt_Password_NhanVien.Text, "SHA1");
        nv.MatKhau_NhanVien = Pass;
        nv.TenNhanVien = txt_TenNhanVien.Text;
        nv.DiaChi = txt_DiaChi.Text;
        nv.DienThoai = txt_DienThoai.Text;
        nv.Email = txt_Email.Text;
        nv.MaPhanQuyen = DropDownList_PhanQuyen.SelectedIndex;
        nv.TrangThai = 1;

        NhanVienBUS.UPDATE(nv);
        Response.Redirect("NhanVien.aspx");
    }
}